package com.zhangmeng.online.exam.entity;

import com.zhangmeng.online.exam.entity.baseEntity.BaseEntity;
import lombok.*;

import javax.persistence.*;
import java.util.*;

/**
 * @author zm
 * @date 2025/2/28 14:45
 * @version: 1.0
 */
@NoArgsConstructor
@ToString(exclude = {"roles"})
@Getter
@Setter
@AllArgsConstructor
@Entity
@Table(name = "user")
public class User extends BaseEntity<Long> {

    @Getter
    public enum Status {
        DISABLED("已停用"),
        VALID("正常"),
        LOCKED("锁定");

        Status(String description) {
            this.description = description;
        }

        private String description;//描述

        public void setDescription(String description) {
            this.description = description;
        }

        public static List<Map<String,Object>> enumListMap(){
            User.Status[] values = User.Status.values();
            List<Map<String, Object>> list = new ArrayList<>();
            for (User.Status value : values) {
                Map<String, Object> map = new HashMap<>();
                String description = value.getDescription();
                map.put("description",description);
                map.put("value",value);
                list.add(map);
            }
            return list;
        }
    }

    private Status status;

    private String username;

    private String password;

    private String email;

    private String phone;

    @ManyToMany(targetEntity = Role.class)
    @JoinTable(name = "user_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    private Set<Role> roles = new HashSet<>();

}
